

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.dataset.GraphData &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.dataset.DistributedSampler" href="mindspore.dataset.DistributedSampler.html" />
    <link rel="prev" title="mindspore.dataset.RandomDataset" href="mindspore.dataset.RandomDataset.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id1">视觉</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id2">文本</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id3">音频</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id4">标准格式</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id5">用户自定义</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.dataset.html#id6">图</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.dataset.GraphData</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id7">采样器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id8">其他</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.dataset.html">mindspore.dataset</a> &raquo;</li>
        
      <li>mindspore.dataset.GraphData</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/dataset/mindspore.dataset.GraphData.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-dataset-graphdata">
<h1>mindspore.dataset.GraphData<a class="headerlink" href="#mindspore-dataset-graphdata" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.dataset.GraphData">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.dataset.</code><code class="sig-name descname">GraphData</code><span class="sig-paren">(</span><em class="sig-param">dataset_file</em>, <em class="sig-param">num_parallel_workers=None</em>, <em class="sig-param">working_mode='local'</em>, <em class="sig-param">hostname='127.0.0.1'</em>, <em class="sig-param">port=50051</em>, <em class="sig-param">num_client=1</em>, <em class="sig-param">auto_shutdown=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData" title="Permalink to this definition">¶</a></dt>
<dd><p>从共享文件或数据库中读取用于GNN训练的图数据集。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>dataset_file</strong> (str) - 数据集文件路径。</p></li>
<li><p><strong>num_parallel_workers</strong> (int, 可选) - 读取数据的工作线程数，默认值：None，使用mindspore.dataset.config中配置的线程数。</p></li>
<li><p><strong>working_mode</strong> (str, 可选) - 设置工作模式，目前支持’local’/’client’/’server’，默认值：’local’。</p>
<ul>
<li><p><strong>local</strong>：用于非分布式训练场景。</p></li>
<li><p><strong>client</strong>：用于分布式训练场景。客户端不加载数据，而是从服务器获取数据。</p></li>
<li><p><strong>server</strong>：用于分布式训练场景。服务器加载数据并可供客户端使用。</p></li>
</ul>
</li>
<li><p><strong>hostname</strong> (str, 可选) - 图数据集服务器的主机名。该参数仅在工作模式设置为 ‘client’ 或 ‘server’ 时有效，默认值：’127.0.0.1’。</p></li>
<li><p><strong>port</strong> (int, 可选) - 图数据服务器的端口，取值范围为1024-65535。此参数仅当工作模式设置为 ‘client’ 或 ‘server’ 时有效，默认值：50051。</p></li>
<li><p><strong>num_client</strong> (int, 可选) - 期望连接到服务器的最大客户端数。服务器将根据该参数分配资源。该参数仅在工作模式设置为 ‘server’ 时有效，默认值：1。</p></li>
<li><p><strong>auto_shutdown</strong> (bool, 可选) - 当工作模式设置为 ‘server’ 时有效。当连接的客户端数量达到 <cite>num_client</cite> ，且没有客户端正在连接时，服务器将自动退出，默认值：True。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>dataset_file</cite> 路径下数据文件不存在或无效。</p></li>
<li><p><strong>ValueError</strong> - <cite>num_parallel_workers</cite> 参数超过系统最大线程数。</p></li>
<li><p><strong>ValueError</strong> - <cite>working_mode</cite> 参数取值不为’local’, ‘client’ 或 ‘server’。</p></li>
<li><p><strong>TypeError</strong> - <cite>hostname</cite> 参数类型错误。</p></li>
<li><p><strong>ValueError</strong> - <cite>port</cite> 参数不在范围[1024, 65535]内。</p></li>
<li><p><strong>ValueError</strong> - <cite>num_client</cite> 参数不在范围[1, 255]内。</p></li>
</ul>
<p><strong>支持平台：</strong></p>
<p><code class="docutils literal notranslate"><span class="pre">CPU</span></code></p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">graph_dataset_dir</span> <span class="o">=</span> <span class="s2">&quot;/path/to/graph_dataset_file&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">graph_dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">GraphData</span><span class="p">(</span><span class="n">dataset_file</span><span class="o">=</span><span class="n">graph_dataset_dir</span><span class="p">,</span> <span class="n">num_parallel_workers</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">features</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_node_feature</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">feature_types</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.dataset.GraphData.get_all_edges">
<code class="sig-name descname">get_all_edges</code><span class="sig-paren">(</span><em class="sig-param">edge_type</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_all_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>获取图的所有边。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>edge_type</strong> (int) - 指定边的类型，在数据集转换为MindRecord格式时，需要指定 <cite>edge_type</cite> 的值，并在此API中对应使用。详见 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html">加载图数据集</a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含边的数组。</p>
<p><strong>异常：</strong></p>
<p><strong>TypeError</strong>：参数 <cite>edge_type</cite> 的类型不为整型。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">edges</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_edges</span><span class="p">(</span><span class="n">edge_type</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_all_neighbors">
<code class="sig-name descname">get_all_neighbors</code><span class="sig-paren">(</span><em class="sig-param">node_list</em>, <em class="sig-param">neighbor_type</em>, <em class="sig-param">output_format=OutputFormat.NORMAL</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_all_neighbors" title="Permalink to this definition">¶</a></dt>
<dd><p>获取 <cite>node_list</cite> 所有节点的相邻节点，以 <cite>neighbor_type</cite> 类型返回。格式的定义参见以下示例：1表示两个节点之间连接，0表示不连接。</p>
<table class="colwidths-given docutils align-default" id="id4">
<caption><span class="caption-text">邻接矩阵</span><a class="headerlink" href="#id4" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"></th>
<th class="head"><p>0</p></th>
<th class="head"><p>1</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>3</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0</p></td>
<td><p>0</p></td>
<td><p>1</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p>1</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
<td><p>1</p></td>
<td><p>0</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p>1</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-odd"><td><p>3</p></td>
<td><p>1</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
<td><p>0</p></td>
</tr>
</tbody>
</table>
<table class="colwidths-given docutils align-default" id="id5">
<caption><span class="caption-text">普通格式</span><a class="headerlink" href="#id5" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>src</p></th>
<th class="head"><p>0</p></th>
<th class="head"><p>1</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>3</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>dst_0</p></td>
<td><p>1</p></td>
<td><p>2</p></td>
<td><p>0</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-odd"><td><p>dst_1</p></td>
<td><p>-1</p></td>
<td><p>-1</p></td>
<td><p>3</p></td>
<td><p>-1</p></td>
</tr>
</tbody>
</table>
<table class="colwidths-given docutils align-default" id="id6">
<caption><span class="caption-text">COO格式</span><a class="headerlink" href="#id6" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
<col style="width: 17%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>src</p></th>
<th class="head"><p>0</p></th>
<th class="head"><p>1</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>3</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>dst</p></td>
<td><p>1</p></td>
<td><p>2</p></td>
<td><p>0</p></td>
<td><p>3</p></td>
<td><p>1</p></td>
</tr>
</tbody>
</table>
<table class="colwidths-given docutils align-default" id="id7">
<caption><span class="caption-text">CSR格式</span><a class="headerlink" href="#id7" title="Permalink to this table">¶</a></caption>
<colgroup>
<col style="width: 29%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>offsetTable</p></th>
<th class="head"><p>0</p></th>
<th class="head"><p>1</p></th>
<th class="head"><p>2</p></th>
<th class="head"><p>4</p></th>
<th class="head"></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>dstTable</p></td>
<td><p>1</p></td>
<td><p>2</p></td>
<td><p>0</p></td>
<td><p>3</p></td>
<td><p>1</p></td>
</tr>
</tbody>
</table>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_list</strong> (Union[list, numpy.ndarray]) - 给定的节点列表。</p></li>
<li><p><strong>neighbor_type</strong> (int) - 指定相邻节点的类型。</p></li>
<li><p><strong>output_format</strong> (OutputFormat, 可选) - 输出存储格式，默认值：mindspore.dataset.OutputFormat.NORMAL，取值范围：[OutputFormat.NORMAL, OutputFormat.COO, OutputFormat.CSR]。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>对于普通格式或COO格式，将返回numpy.ndarray类型的数组表示相邻节点。如果指定了CSR格式，将返回两个numpy.ndarray数组，第一个表示偏移表，第二个表示相邻节点。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>node_list</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>neighbor_type</cite> 的类型不为整型。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.dataset.engine</span> <span class="kn">import</span> <span class="n">OutputFormat</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">neighbors</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_neighbors</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">neighbor_type</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">neighbors_coo</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_neighbors</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">neighbor_type</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                                                <span class="n">output_format</span><span class="o">=</span><span class="n">OutputFormat</span><span class="o">.</span><span class="n">COO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">offset_table</span><span class="p">,</span> <span class="n">neighbors_csr</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_neighbors</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">neighbor_type</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="gp">... </span>                                                              <span class="n">output_format</span><span class="o">=</span><span class="n">OutputFormat</span><span class="o">.</span><span class="n">CSR</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_all_nodes">
<code class="sig-name descname">get_all_nodes</code><span class="sig-paren">(</span><em class="sig-param">node_type</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_all_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>获取图中的所有节点。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_type</strong> (int) - 指定节点的类型。在数据集转换为MindRecord格式时，需要指定 <cite>node_type</cite> 的值，并在此API中对应使用。详见 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html">加载图数据集</a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含节点的数组。</p>
<p><strong>异常：</strong></p>
<p><strong>TypeError</strong>：参数 <cite>node_type</cite> 的类型不为整型。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_edges_from_nodes">
<code class="sig-name descname">get_edges_from_nodes</code><span class="sig-paren">(</span><em class="sig-param">node_list</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_edges_from_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>从节点获取边。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_list</strong> (Union[list[tuple], numpy.ndarray]) - 含一个或多个图节点ID对的列表。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，含一个或多个边ID的数组。</p>
<p><strong>异常：</strong></p>
<p><strong>TypeError</strong>：参数 <cite>edge_list</cite> 的类型不为列表或numpy.ndarray。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">edges</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_edges_from_nodes</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="p">[(</span><span class="mi">101</span><span class="p">,</span> <span class="mi">201</span><span class="p">),</span> <span class="p">(</span><span class="mi">103</span><span class="p">,</span> <span class="mi">207</span><span class="p">)])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_edge_feature">
<code class="sig-name descname">get_edge_feature</code><span class="sig-paren">(</span><em class="sig-param">edge_list</em>, <em class="sig-param">feature_types</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_edge_feature" title="Permalink to this definition">¶</a></dt>
<dd><p>获取 <cite>edge_list</cite> 列表中边的特征，以 <cite>feature_types</cite> 类型返回。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>edge_list</strong> (Union[list, numpy.ndarray]) - 包含边的列表。</p></li>
<li><p><strong>feature_types</strong> (Union[list, numpy.ndarray]) - 包含给定特征类型的列表。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含特征的数组。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>edge_list</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>feature_types</cite> 的类型不为列表或numpy.ndarray。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">edges</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_edges</span><span class="p">(</span><span class="n">edge_type</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">features</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_edge_feature</span><span class="p">(</span><span class="n">edge_list</span><span class="o">=</span><span class="n">edges</span><span class="p">,</span> <span class="n">feature_types</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_neg_sampled_neighbors">
<code class="sig-name descname">get_neg_sampled_neighbors</code><span class="sig-paren">(</span><em class="sig-param">node_list</em>, <em class="sig-param">neg_neighbor_num</em>, <em class="sig-param">neg_neighbor_type</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_neg_sampled_neighbors" title="Permalink to this definition">¶</a></dt>
<dd><p>获取 <cite>node_list</cite> 列表中节所有点的负样本相邻节点，以 <cite>neg_neighbor_type</cite> 类型返回。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_list</strong> (Union[list, numpy.ndarray]) - 包含节点的列表。</p></li>
<li><p><strong>neg_neighbor_num</strong> (int) - 采样的相邻节点数量。</p></li>
<li><p><strong>neg_neighbor_type</strong> (int) - 指定负样本相邻节点的类型。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含相邻节点的数组。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>node_list</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>neg_neighbor_num</cite> 的类型不为整型。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>neg_neighbor_type</cite> 的类型不为整型。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">neg_neighbors</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_neg_sampled_neighbors</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">neg_neighbor_num</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
<span class="gp">... </span>                                                        <span class="n">neg_neighbor_type</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_nodes_from_edges">
<code class="sig-name descname">get_nodes_from_edges</code><span class="sig-paren">(</span><em class="sig-param">edge_list</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_nodes_from_edges" title="Permalink to this definition">¶</a></dt>
<dd><p>从图中的边获取节点。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>edge_list</strong> (Union[list, numpy.ndarray]) - 包含边的列表。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含节点的数组。</p>
<p><strong>异常：</strong></p>
<p><strong>TypeError</strong> 参数 <cite>edge_list</cite> 不为列表或ndarray。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_node_feature">
<code class="sig-name descname">get_node_feature</code><span class="sig-paren">(</span><em class="sig-param">node_list</em>, <em class="sig-param">feature_types</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_node_feature" title="Permalink to this definition">¶</a></dt>
<dd><p>获取 <cite>node_list</cite> 中节点的特征，以 <cite>feature_types</cite> 类型返回。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_list</strong> (Union[list, numpy.ndarray]) - 包含节点的列表。</p></li>
<li><p><strong>feature_types</strong> (Union[list, numpy.ndarray]) - 指定特征的类型。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含特征的数组。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>node_list</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>feature_types</cite> 的类型不为列表或numpy.ndarray。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">features</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_node_feature</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">feature_types</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.get_sampled_neighbors">
<code class="sig-name descname">get_sampled_neighbors</code><span class="sig-paren">(</span><em class="sig-param">node_list</em>, <em class="sig-param">neighbor_nums</em>, <em class="sig-param">neighbor_types</em>, <em class="sig-param">strategy=SamplingStrategy.RANDOM</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.get_sampled_neighbors" title="Permalink to this definition">¶</a></dt>
<dd><p>获取已采样相邻节点信息。此API支持多跳相邻节点采样。即将上一次采样结果作为下一跳采样的输入，最多允许6跳。采样结果平铺成列表，格式为[input node, 1-hop sampling result, 2-hop samling result …]</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>node_list</strong> (Union[list, numpy.ndarray]) - 包含节点的列表。</p></li>
<li><p><strong>neighbor_nums</strong> (Union[list, numpy.ndarray]) - 每跳采样的相邻节点数。</p></li>
<li><p><strong>neighbor_types</strong> (Union[list, numpy.ndarray]) - 每跳采样的相邻节点类型。</p></li>
<li><p><strong>strategy</strong> (SamplingStrategy, 可选) - 采样策略，默认值：mindspore.dataset.SamplingStrategy.RANDOM。取值范围：[SamplingStrategy.RANDOM, SamplingStrategy.EDGE_WEIGHT]。</p>
<ul>
<li><p><strong>SamplingStrategy.RANDOM</strong>：随机抽样，带放回采样。</p></li>
<li><p><strong>SamplingStrategy.EDGE_WEIGHT</strong>：以边缘权重为概率进行采样。</p></li>
</ul>
</li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含相邻节点的数组。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>node_list</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>neighbor_nums</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>neighbor_types</cite>  的类型不为列表或numpy.ndarray。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">neighbors</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_sampled_neighbors</span><span class="p">(</span><span class="n">node_list</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">neighbor_nums</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>
<span class="gp">... </span>                                                <span class="n">neighbor_types</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.graph_info">
<code class="sig-name descname">graph_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.graph_info" title="Permalink to this definition">¶</a></dt>
<dd><p>获取图的元信息，包括节点数、节点类型、节点特征信息、边数、边类型、边特征信息。</p>
<p><strong>返回：</strong></p>
<p>dict，图的元信息。键为 <cite>node_num</cite> 、 <cite>node_type</cite> 、 <cite>node_feature_type</cite> 、 <cite>edge_num</cite> 、 <cite>edge_type</cite> 和 <cite>edge_feature_type</cite> 。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.GraphData.random_walk">
<code class="sig-name descname">random_walk</code><span class="sig-paren">(</span><em class="sig-param">target_nodes</em>, <em class="sig-param">meta_path</em>, <em class="sig-param">step_home_param=1.0</em>, <em class="sig-param">step_away_param=1.0</em>, <em class="sig-param">default_node=-1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.GraphData.random_walk" title="Permalink to this definition">¶</a></dt>
<dd><p>在节点中的随机游走。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>target_nodes</strong> (list[int]) - 随机游走中的起始节点列表。</p></li>
<li><p><strong>meta_path</strong> (list[int]) - 每个步长的节点类型。</p></li>
<li><p><strong>step_home_param</strong> (float, 可选) - 返回 <a class="reference external" href="https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf">node2vec算法</a> 中的超参，默认值：1.0。</p></li>
<li><p><strong>step_away_param</strong> (float, 可选) - <a class="reference external" href="https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf">node2vec算法</a> 中的in和out超参，默认值：1.0。</p></li>
<li><p><strong>default_node</strong> (int, 可选) - 如果找不到更多相邻节点，则为默认节点，默认值：-1，表示不给定节点。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>numpy.ndarray，包含节点的数组。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> - 参数 <cite>target_nodes</cite> 的类型不为列表或numpy.ndarray。</p></li>
<li><p><strong>TypeError</strong> - 参数 <cite>meta_path</cite> 的类型不为列表或numpy.ndarray。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">nodes</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">get_all_nodes</span><span class="p">(</span><span class="n">node_type</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">walks</span> <span class="o">=</span> <span class="n">graph_dataset</span><span class="o">.</span><span class="n">random_walk</span><span class="p">(</span><span class="n">target_nodes</span><span class="o">=</span><span class="n">nodes</span><span class="p">,</span> <span class="n">meta_path</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.dataset.DistributedSampler.html" class="btn btn-neutral float-right" title="mindspore.dataset.DistributedSampler" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.dataset.RandomDataset.html" class="btn btn-neutral float-left" title="mindspore.dataset.RandomDataset" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>